# @Time:2021/6/11 19:54
# @Author:5120195554王欣霏
# -*- coding = utf-8 -*-

import os
import pygame
import enum
import actor
from scene import SceneResult


class CattleBattleStatus(enum.IntEnum):
    '''
    牛魔王打斗
    '''
    Station = 0
    Fight = 1
    Die = 2
    DieOver = 3


class BattleCattle(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.die = actor.DirAction('cattle', 'die', '0762-4cbbea5a-', 4, 11, False)
        # 战斗
        self.fight = actor.DirAction('cattle', 'fight', '0618-3c4fe166-', 4, 13, False)
        # 站立
        self.station = actor.DirAction('cattle', 'station', '1644-a85e8726-', 4, 2, False)
        self.status = CattleBattleStatus.Station
        self.result = SceneResult.Ongoing
        self.hp = 20
        self.pos_x = 300
        self.pos_y = 120

    def attack_hp(self, hp):
        self.hp += hp
        if self.hp <= 0:
            self.set_status(CattleBattleStatus.Die)


    def set_status(self, status):
        self.status = status
        if self.status == CattleBattleStatus.Fight:
            self.fight.reset()
        elif self.status == CattleBattleStatus.Station:
            self.station.reset()
        elif self.status == CattleBattleStatus.Die:
            self.die.reset()

    def action_over(self):
        if self.status == CattleBattleStatus.Fight:
            return self.fight.is_end()
        elif self.status == CattleBattleStatus.Die:
            if self.die.is_end():
                self.status = CattleBattleStatus.DieOver
            return self.die.is_end()
        elif self.status == CattleBattleStatus.Station:
            return self.station.is_end()

    def draw(self, surface: pygame.Surface):
        dir = 2
        if self.status == CattleBattleStatus.Station:
            image = self.station.get_curr_frame(dir)
        elif self.status == CattleBattleStatus.Fight:
            image = self.fight.get_curr_frame(dir)
        elif self.status == CattleBattleStatus.Die:
            image = self.die.get_curr_frame(dir)
        elif self.status == CattleBattleStatus.DieOver:
            image = self.die.get_curr_frame(dir)
        if image:
            pygame.draw.rect(surface, pygame.Color(255, 255, 255), pygame.Rect(400, 60, self.hp / 2, 5))
            surface.blit(image, (self.pos_x, self.pos_y))
